from humiture import *

class Zhongsheng(Humiture):
    # 寄存器类型
    # 保持寄存器地址
    __ID_REG_ADDR = 0x0a
    __BAUD_REG_ADDR = 0x0b
    # 输入寄存器地址
    __TEMPERATURE_REG_ADDR = 0x00
    __HUMIDITY_REG_ADDR = 0x01

    # 功能码定义
    __AD_MAINTAIN_REG = 0x03
    __WRITE_MAINTAIN_REG = 0x06
    __AD_INPUT_REG = 0x04   # 温湿度

    def __init__(self, id) -> None:
        super().__init__(id)
    
    def __no2baud(self, no):
        if no == 0:
            return 4800
        elif no == 1:
            return 9600
        elif no == 2:
            return 14400
        elif no == 3:
            return 19200
        elif no == 4:
            return 38400
        elif no == 5:
            return 56000
        elif no == 6:
            return 57600
        elif no == 7:
            return 115200
        elif no == 8:
            return 128000
        elif no == 9:
            return 256000
        
    def __baud2no(self, baud):
        if baud == 4800:
            return 0
        elif baud == 9600:
            return 1
        elif baud == 14400:
            return 2
        elif baud == 19200:
            return 3
        elif baud == 38400:
            return 4
        elif baud == 56000:
            return 5
        elif baud == 57600:
            return 6
        elif baud == 115200:
            return 7
        elif baud == 128000:
            return 8
        elif baud == 256000:
            return 9
        
    def humitureRead(self):
        return super().humitureRead(self.__AD_INPUT_REG, self.__TEMPERATURE_REG_ADDR)
    
    def idRead(self):
        return super().idRead(self.__AD_MAINTAIN_REG, self.__AD_MAINTAIN_REG)
    
    def writeId(self, id):
        return super().writeId(self.__WRITE_MAINTAIN_REG, self.__WRITE_MAINTAIN_REG, id)
    
    def writeBaud(self, baud):
        return super().writeBaud(self.__WRITE_MAINTAIN_REG, self.__WRITE_MAINTAIN_REG, baud)
    